﻿using System.Web.Mvc;

namespace Mvc4Demo.Core
{
    public class PdfViewEngineProvider : VirtualPathProviderViewEngine
    {
        public PdfViewEngineProvider()
        {
            ViewLocationFormats = new string[] { "~/Views/{1}/{0}.tpdf", "~/Views/Shared/{0}.tpdf" };
            PartialViewLocationFormats = ViewLocationFormats;
        }

        protected override IView CreatePartialView(ControllerContext controllerContext, string partialPath)
        {
            return CreateCustomView(controllerContext, partialPath);
        }

        protected override IView CreateView(ControllerContext controllerContext, string viewPath, string masterPath)
        {
            return CreateCustomView(controllerContext, viewPath);
        }

        private static PdfView CreateCustomView(ControllerContext controllerContext, string viewPath)
        {
            var physicalpath = controllerContext.HttpContext.Server.MapPath(viewPath);
            return new PdfView(physicalpath);
        }

    }
}